/* sod.t - SO_MSTR delete trigger                                            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.1 $                                                         */
/*                                                                           */
/* This program will delete external storefront order xref records from      */
/* qad_wkfl when corresponding so_mstr records are deleted.                  */
/*                                                                           */
/* $Revision: 1.1 $   BY: John Pison            DATE:01/25/01   ECO: *N0VZ* */
/*                                                                           */
/*V8:ConvertMode=NoConvert                                                   */


TRIGGER PROCEDURE FOR DELETE OF so_mstr.

/*fdn*/    {mfdeclre.i }
/*fdn*/    define new shared work-table wf_old_so_mstr like so_mstr.


/* Identifier for procedure that adds these workfile records */
&SCOPED-DEFINE WORKFILE-KEY ncapis.p

/* Delete storefront order xref record for the current SO */
for first qad_wkfl exclusive-lock where
   qad_key1 = "{&WORKFILE-KEY}" and
   qad_key2 = so_nbr:

   delete qad_wkfl.

end.  /* for */

HK:
do:
    if can-find(first dt_mstr where dt_table = "so_mstr" and dt_type = "SYNC") then
        run CreateSyncFlag(input "DEL", input recid(so_mstr), input "so_mstr").

    if not can-find ( first dt_mstr where dt_table = "so_mstr" and dt_type = "DEL" ) then leave HK.
    
    if not can-find ( first wf_old_so_mstr ) then do:
        create wf_old_so_mstr.
        if recid(wf_old_so_mstr)= -1 then .
    end.
    
    buffer-copy so_mstr to wf_old_so_mstr no-error.

    for first dt_mstr no-lock where dt_table = "so_mstr" and dt_type = "DEL" :
    
        run CreateDthist(input dt_table, input dt_field, input dt_type, input "", input "", 
            input recid(so_mstr), input so_mstr.so_nbr, input "", input "", input "",
            input "", input "", input "", input "") .
		
    end.
end.

{hkdttrans.i}
